package apitest.comparator;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

import org.junit.Test;

public class ComparatorTest {
    public static void main(String[] args) {
        Person p1 = new Person(10);
        Person p2 = new Person(20);
        Person[] ps = new Person[]{p1,p2};

        Arrays.sort(ps, new PersonCompare());
        for (Person p : ps) {
            System.out.println(p.age);
        }
    }

    @Test
    public void test01(){
        int[] nums = new int[]{3,2,3,1,2,4,5,5,6};
        PriorityQueue<Integer> minHeap = new PriorityQueue<>();
        for (int i = 0; i < nums.length; i++) {
            minHeap.add(nums[i]);
        }
        while(!minHeap.isEmpty()){
            System.out.println(minHeap.poll());
        }
        System.out.println("====================");
        minHeap = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        for (int i = 0; i < nums.length; i++) {
            minHeap.add(nums[i]);
        }
        while(!minHeap.isEmpty()){
            System.out.println(minHeap.poll());
        }
    }
}
